package com.handu.luna.core.domain;

import java.io.IOException;
import java.net.URL;


/**
 * 项目启动的时候自动启动redis
 * @author malei
 *
 */
//@Service
public class RedisAutoStart {
	
	private Process process;
	
	//@PostConstruct
	public void start(){
		try {
			//获取操作系统位数32 64
			String model = System.getProperty("sun.arch.data.model");
			String bin = "redis/x" + model + "/" + "redis-server.exe";
			URL executeBin = this.getClass().getResource(bin);
			if(executeBin == null)
				executeBin = this.getClass().getClassLoader().getResource(bin);
			process = Runtime.getRuntime().exec(executeBin.getFile());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	//@PreDestroy
	public void destroy(){
		process.destroy();
	}
}
